﻿#include "TButton.h"
#include "qpainter.h"
#include "qdebug.h"

TButton::TButton(QWidget *parent): QPushButton(parent)
{

}

void TButton::enterEvent(QEvent *)
{

}

void TButton::leaveEvent(QEvent *)
{

}

void TButton::paintEvents(QPaintEvent *)
{
    //绘制准备工作,启用反锯齿
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);

    //绘制背景
    drawBg(&painter);
    //绘制文字
    drawText(&painter);
    //绘制图标
    drawIcon(&painter);
    //绘制边框线条
    drawLine(&painter);
    //绘制倒三角
    drawTriangle(&painter);
}

void TButton::drawBg(QPainter *painter)
{
    painter->save();
    painter->setPen(Qt::NoPen);

    int width = this->width();
    int height = this->height();

    painter->setBrush(QColor("white"));
    QRect bgRect = QRect(0,0,width,height);
    painter->drawRect(bgRect);

    painter->restore();
}

void TButton::drawText(QPainter *painter)
{
    painter->save();
    painter->setBrush(Qt::NoBrush);

    //根据当前状态选择对应颜色
    QColor textColor=QColorConstants::Black;
//    if (isChecked()) {
//        textColor = checkTextColor;
//    } else if (hover) {
//        textColor = hoverTextColor;
//    } else {
//        textColor = normalTextColor;
//    }

    //QRect textRect = QRect(paddingLeft, paddingTop, width() - paddingLeft - paddingRight, height() - paddingTop - paddingBottom);

    int width = this->width();
    int height = this->height();
    QRect textRect = QRect(0,0,width,height);
    painter->setPen(QColor("black"));
    textAlign=TextAlign::TextAlign_Left;
    painter->drawText(textRect, textAlign | Qt::AlignVCenter, "sdsds");

    painter->restore();
}

void TButton::drawIcon(QPainter *painter)
{

}

void TButton::drawLine(QPainter *painter)
{

}

void TButton::drawTriangle(QPainter *painter)
{

}
